package org.jmc.refmanager.web.wicket.model;

import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.jmc.refmanager.domain.model.Adresse;
import org.jmc.refmanager.domain.model.Adresse.AdressePK;
import org.jmc.refmanager.domain.service.AdresseManager;

public class AdresseModel extends LoadableDetachableModel<Adresse> {
	private static final long serialVersionUID = 1L;

	@SpringBean(name="adresseManager")
	private AdresseManager adresseManager;
	private AdressePK pk;
	
	/**
	 * @param object
	 */
	public AdresseModel(Adresse adresse) {
		super(); // super(adresse);
		InjectorHolder.getInjector().inject(this);
		this.pk = adresse.getPk();
	}


	@Override
	protected Adresse load() {
		if (this.pk == null) {
			return new Adresse();
		} else {
			return adresseManager.findByPK(this.pk);
		}
	}

}
